package com.ruoyi.backend.controller;

import com.ruoyi.backend.domain.TService;
import com.ruoyi.backend.service.ITServiceService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务Controller
 * 
 * @author wjr
 * @date 2025-09-23
 */
@RestController
@RequestMapping("/backend/t_service")
@Api(tags = "服务")
public class TServiceController extends BaseController
{
    @Autowired
    private ITServiceService tServiceService;

    /**
     * 查询服务列表
     */
    @PreAuthorize("@ss.hasPermi('backend:t_service:list')")
    @GetMapping("/list")
    @ApiOperation("查询服务列表-分页")
    public TableDataInfo list(TService tService)
    {
        startPage();
        List<TService> list = tServiceService.selectTServiceList(tService);
        return getDataTable(list);
    }

    /**
     * 获取服务列表
     */
    @PreAuthorize("@ss.hasPermi('backend:t_service:list')")
    @GetMapping("/getServiceList")
    @ApiOperation("获取服务列表-不分页")
    public AjaxResult getServiceList(TService tService)
    {
        List<TService> list = tServiceService.selectTServiceList(tService);
        return success(list);
    }

    /**
     * 获取服务详细信息
     */
    @PreAuthorize("@ss.hasPermi('backend:t_service:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取服务详细信息")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(tServiceService.selectTServiceById(id));
    }

    /**
     * 新增服务
     */
    @PreAuthorize("@ss.hasPermi('backend:t_service:add')")
    @Log(title = "服务", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增服务")
    public AjaxResult add(@RequestBody TService tService)
    {
        return toAjax(tServiceService.insertTService(tService));
    }

    /**
     * 修改服务
     */
    @PreAuthorize("@ss.hasPermi('backend:t_service:edit')")
    @Log(title = "服务", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改服务")
    public AjaxResult edit(@RequestBody TService tService)
    {
        return toAjax(tServiceService.updateTService(tService));
    }

    /**
     * 删除服务
     */
    @PreAuthorize("@ss.hasPermi('backend:t_service:remove')")
    @Log(title = "服务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除服务")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(tServiceService.deleteTServiceByIds(ids));
    }

    /**
     * 导出服务列表
     */
    /*@PreAuthorize("@ss.hasPermi('backend:t_service:export')")
    @Log(title = "服务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TService tService)
    {
        List<TService> list = tServiceService.selectTServiceList(tService);
        ExcelUtil<TService> util = new ExcelUtil<TService>(TService.class);
        util.exportExcel(response, list, "服务数据");
    }*/

}
